<?php

namespace server\dao;

use Yii;
use yii\mongodb\Query;

/**
 * This is the model class for collection "runtime_202006".
 *
 * @property \MongoDB\BSON\ObjectID|string $_id
 * @property mixed $id
 * @property mixed $info
 */
class States extends \common\core\server\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function collectionName()
    {
        return 'states';
    }

    /**
     * {@inheritdoc}
     */
    public function attributes()
    {
        return [
            '_id',
            'uuid',
            'timestamp',
            'device_warning',
            'module_warning'
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['time', 'device_warning', 'module_warning'], 'safe']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            '_id' => 'ID',
            'time' => 'Time',
            'device_warning' => 'Device Warning',
            'module' => 'Module',
        ];
    }

    public function getSates($ip)
    {
        $query = new Query();
        $query->from($this->collectionName());
        $query->andWhere(['uuid' => $ip]);
        return $query->one();
    }

    public function getSatesList()
    {
        $query = new Query();
        $query->from($this->collectionName());
        return $query->all();
    }
}
